<?php
session_start();
include 'user.php';
include 'talk.php';
$user = new User;
$user->init_for_db($_SESSION['id']);
$status = $user->get_status();
if($status == 0)
{
    $user->set_status(1);
}
// 用户要更换聊天对象
else if($status == 2)
{
    $talker = new Talker();
    $other_session_id = $talker->get_other_session_id($user->get_session_id());
    // del talker 
    $talker->init($user->get_session_id(),$other_session_id);
    $talker->del();
    $other_user = new User;
    $other_user->init_for_db($other_session_id);
    $user->set_status(1);
    $other_user->set_status(1);
}
$session_id = $user->find_user();
if($session_id == FALSE)
    die("FALSE");
else
{
    $talker = new Talker;
    $talker->init($user->get_session_id(),$session_id);
    if($user->get_status() == 2)
	die("TRUE");
    // 更改状态并插入数据库
    $user->set_status(2);
    $user->init_for_db($session_id);
    $user->set_status(2);
    $talker->insert();
    die("TRUE");
}
?>